package com.boot.web.exception;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description Web应用错误处理器
 * @date 2020/2/16 19:51
 **/

public class ExceptionHandlerManager {

    private final List<ModuleExceptionHandler> handlers;

    public ExceptionHandlerManager() {
        this.handlers = new ArrayList<>(10);
    }

    public ExceptionHandlerManager addHandler(ModuleExceptionHandler handler) {
        handlers.add(handler);
        return this;
    }

    public ExceptionHandlerManager apply() {
        handlers.sort(Comparator.comparingInt(ModuleExceptionHandler::order));
        return this;
    }

    public List<ModuleExceptionHandler> getHandlers() {
        return handlers;
    }
}
